// pages/chengyu/chengyu.js
import indexApi from '../../api/index'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cyInfo: {},
    loadtext: false,
    text: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },
  async getInfo(e) {
    if (e.detail.value ) {
      this.setData({
        loadtext: true,
        text: e.detail.value,
        cyInfo: {}
      })
      const res = await indexApi.getChengyu({ key: '9b939f265072c9e6f89756c1ac62b01c', word: e.detail.value })
      if (res.data.error_code == 0) {
        this.setData({
          cyInfo: res.data.result,
          loadtext: false,
        })
      } else {
        wx.showToast({
          title: res.data.reason,
          icon: 'none',
          duration: 2000
        });
        this.setData({
          loadtext: false,
          text: '',
          cyInfo: {},
        })
      }
    }
  }

})